﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SIIV.Business;
using SIIV.Data;

namespace SIIV.View.Web.Controllers
{
    public abstract class BaseController : Controller
    {
        private static AnimalBusiness _animalBusiness;
        protected AnimalBusiness Animales
        {
            get
            {
                if (_animalBusiness == null)
                {
                    _animalBusiness = new AnimalBusiness();
                }
                return _animalBusiness;
            }
        }

        private static ProductorBusiness _productorBusiness;
        protected ProductorBusiness Productores
        {
            get
            {
                if (_productorBusiness == null)
                {
                    _productorBusiness = new ProductorBusiness();
                }
                return _productorBusiness;
            }
        }

        private static CampoBusiness _campoBusiness;
        protected CampoBusiness Campos
        {
            get
            {
                if (_campoBusiness == null)
                {
                    _campoBusiness = new CampoBusiness();
                }
                return _campoBusiness;
            }
        }

        private static UsuarioBusiness _usuarioBusiness;
        protected UsuarioBusiness Usuarios
        {
            get
            {
                if (_usuarioBusiness == null)
                {
                    _usuarioBusiness = new UsuarioBusiness();
                }
                return _usuarioBusiness;
            }
        }

        private static NotificacionBusiness _notificacionBusiness;
        protected NotificacionBusiness Notificaciones
        {
            get
            {
                if (_notificacionBusiness == null)
                {
                    _notificacionBusiness = new NotificacionBusiness();
                }
                return _notificacionBusiness;
            }
        }

        private static MuestraBusiness _muestraBusiness;
        protected MuestraBusiness Muestras
        {
            get
            {
                if (_muestraBusiness == null)
                {
                    _muestraBusiness = new MuestraBusiness();
                }
                return _muestraBusiness;
            }
        }

        protected Usuario VeterinarioLogueado { get { return Session["Usuario"] as Usuario; } }

        protected override void OnAuthorization(AuthorizationContext filterContext)
        {
            if (Session["Usuario"] != null)
            {
                HttpContext.User = new CustomPrincipal(new CustomIdentity(Session["Usuario"] as SIIV.Data.Usuario));
            }
            base.OnAuthorization(filterContext);
        }

        public ActionResult Ayuda()
        {
            return View("Ayuda");
        }
    }
}
